#include <string.h>

char *strncpy(char *dest, const char *src, size_t count) {
	char *tmp = dest;
	size_t len = strlen(src);

	if (count > len)
		count = len;

	for (size_t i = 0; i < count; i++) {
		dest[i] = src[i];
	}
	dest[count] = '\0';

	return tmp;
}

#ifdef _TEST_
#include <stdio.h>

int main() {
	char str1[] = "To be or not to be";
	char str2[6];
	strncpy(str2, str1, 5);
	str2[5] = '\0';
	puts(str2);
	return 0;
}

#endif
